﻿@using Lib.core;
@using Lib.helper;

@using Bll;
@using Model;
@using Model.Sys;
@using Hiwjcn.Web.Models.Link;
@{
    Layout = null;

    var model = ViewData["model"] as LinkListViewModel;
    if (model == null) { model = new LinkListViewModel(); }
}

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
          "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <!-- header page -->
    @Html.Partial(IncludePath("header"))
</head>

<body>
    @Html.Partial(IncludePath("body_top"))
    @Html.Partial(IncludePath("manage_nav"))

    <div class="container-fluid" style="margin-top: 20px;">
        <div class="row">
            <div class="col-md-12">
                <div class="right" style="padding:20px 0;">
                    <a href="/admin/link/linkedit/?link_type=@(model.LinkType)" class="btn btn-primary layer_win" target="_blank">添加</a>
                </div>
            </div>
            <div class="col-md-12">
                <div class="box">
                    @{
                        if (ValidateHelper.IsPlumpList(model.LinkList))
                        {
                            <table class="table table-hover">
                                <tbody>
                                    @foreach (var link in model.LinkList)
                                    {
                                        <tr>
                                            <td>
                                                @if (ValidateHelper.IsPlumpString(link.Image))
                                                {
                                                    <img src="@(link.Image)" alt="" style="width:150px;height:auto;" />
                                                }
                                            </td>
                                            <td>@(link.Url)</td>
                                            <td>@(link.Title)</td>
                                            <td>@(link.Name)</td>
                                            <td>@(link.Target)</td>
                                            <td>@(link.OrderNum)</td>
                                            <td>@(link.LinkType)</td>
                                            <td>
                                                <a href="/admin/link/linkedit/?id=@(link.LinkID)" class="btn btn-primary btn-sm layer_win" target="_blank">编辑</a>
                                                <button class="btn btn-x btn-sm del" data-id='@(link.LinkID)'>删除</button>
                                            </td>
                                        </tr>
                                    }
                                </tbody>
                            </table>
                        }
                        else
                        {
                            <div class="alert alert-danger">
                                没有任何链接
                            </div>
                        }
                    }
                </div>
            </div>
        </div>

    </div>

    <script type="text/javascript">
        $(function () {
            $('.del').click(function () {
                if (!confirm('确定删除？')) { return; }
                var id = $(this).attr('data-id');
                postJson('/admin/link/DeleteLinkAction/', { id: id }, function (res) {
                    if (res && res.success) {
                        alert('删除成功');
                        window.location.reload();
                    }
                    else {
                        alert(res.msg);
                    }
                });
                return false;
            });
        });
    </script>

    @Html.Partial(IncludePath("body_bottom"))
</body>
</html>
